<link rel="stylesheet" type="text/css" href="http://{$strona.domena}/P/dhtmlxGrid/codebase/dhtmlxgrid.css" />
<script type="text/javascript" src="http://{$strona.domena}/P/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
<script type="text/javascript" src="http://{$strona.domena}/P/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>
<script type="text/javascript" src="http://{$strona.domena}/P/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
<script type="text/javascript" src="http://{$strona.domena}/P/dhtmlxGrid/codebase/ext/dhtmlxgrid_filter.js"></script>
<script type="text/javascript" src="http://{$strona.domena}/P/dhtmlxToolbar/codebase/dhtmlxcommon.js"></script>
<script type="text/javascript" src="http://{$strona.domena}/P/dhtmlxToolbar/codebase/dhtmlxtoolbar.js"></script>
<link rel="stylesheet" type="text/css" href="http://{$strona.domena}/P/dhtmlxToolbar/codebase/skins/dhtmlxtoolbar_dhx_web.css" />

<div class="zawartosc">
    <div id="toolbarDiv"></div>
    <div id="mygrid_container" style="height:500px; width: 100%"></div>
</div>

<script type="text/javascript">
    /* Grid */
    var grid;
    grid = new dhtmlXGridObject('mygrid_container');
    grid.setImagePath("http://{$strona.domena}/P/icons/");
    grid.setHeader("Id,Tag,Powiązane aktualności");
    grid.setInitWidths("40,120,*");
    grid.setColAlign("left,center,center");
    grid.setSkin("light");
    grid.setColSorting("int,str,str,str,str,date,int,str,str");
    grid.init();
    grid.loadXML('/cms/aktualnosci/tagi/akcja,xml.html', function() {
        grid.attachHeader("#rspan,<div id='tag_flt' style='padding-right:10px;'></div>,#rspan");
        $('#tag_flt').append('<input type="text" style="width: 100%; border:1px solid gray;" onClick="(arguments[0]||window.event).cancelBubble=true;" onKeyUp="filterBy()">');
        //block sorting and resize actions for second row;
        grid.hdr.rows[2].onmousedown = grid.hdr.rows[2].onclick = function(e) { (e || event).cancelBubble = true; }
        grid.setSizes();
    });
    function filterBy() {
        //uchwyt,numer kolumny w dhtmlx
        var pola = [[$('#tag_flt').children()[0].value.toLowerCase(),1]];
        //filtrowanie
        for (var i = 0; i < grid.getRowsNum(); i++) {
            var str;
            for(j in pola) {
                if(((pola[j])[0]) != '') {
                    str = grid.cells2(i, (pola[j])[1]).getValue().toString().toLowerCase();
                    if(str.indexOf((pola[j])[0]) == 0)
                        grid.setRowHidden(grid.getRowId(i), false);
                    else
                        grid.setRowHidden(grid.getRowId(i), true);
                }
                else {
                    
                }
            }
            //usuwanie filtrowania
            var odswiez = true;
            for(j in pola){
                if(((pola[j])[0]) != '')
                    odswiez = false;
            }
            if(odswiez){
                grid.setRowHidden(grid.getRowId(i), false);
            }
        }
    }
    /* Toolbar */
    var toolbar = new dhtmlXToolbarObject('toolbarDiv','dhx_web');
    toolbar.setIconsPath("http://{$strona.domena}/P/icons/");
    toolbar.addButton(1, 1, "Usuń niepowiązane tagi",'link_delete.png');
    toolbar.addButton(2, 2, "Edytuj",'pencil.png','pencil.png');
    toolbar.addButton(3, 3, "Usuń",'cross.png','cross.png');
    toolbar.disableItem(2);
    toolbar.disableItem(3);
    toolbar.attachEvent("onClick", function(id){
        switch(id)
        {
            case '1':
                if(confirm('Napewno usunąć niepowiązane tagi?')){
                    dhtmlxAjax.getSync('/cms/aktualnosci/tagi/edycja/akcja,usunNiePowiazane.html');
                    grid.updateFromXML('/cms/aktualnosci/tagi/akcja,xml.html', true, true, false);
                }
                break;
            case '2':
                window.location = '/cms/aktualnosci/tagi/edycja/akcja,edytuj,id,'+grid.getSelectedId()+'.html';
                break;
            case '3':
                if(confirm('Napewno usunąć wybrany tag?')){
                    dhtmlxAjax.getSync('/cms/aktualnosci/tagi/edycja/akcja,usun,id,'+grid.getSelectedId()+'.html');
                    grid.updateFromXML('/cms/aktualnosci/tagi/akcja,xml.html', true, true, false);
                }
                break;
            default:
                alert('Wybrałeś nieobsługiwaną opcję!');
        }
    });
    grid.attachEvent("onRowSelect", function(id,ind){
        toolbar.enableItem(2);
        toolbar.enableItem(3);
    });
</script>
